﻿<inter:PluginConfigForm x:Class="Convertor.Plugin.WebDownloader.ConfigForm"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:inter="clr-namespace:Convertor.Interface;assembly=Convertor.Interface"
             xmlns:sm="clr-namespace:Wpf.CommonTools.SystemExtension;assembly=Wpf.CommonTools"
             xmlns:conv="clr-namespace:Wpf.CommonTools.Converter;assembly=Wpf.CommonTools"
             xmlns:local="clr-namespace:Convertor.Plugin.WebDownloader"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             Loaded="UserControl_Loaded_1">
    <inter:PluginConfigForm.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Convertor;component\Assets\Style.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.zh.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.en.xaml"/>
            </ResourceDictionary.MergedDictionaries>


            <conv:FindUILanguageConverter x:Key="FindUILanguageConverter"/>
            <conv:EnumToVsibleConverter x:Key="EnumToVsibleConverter"/>
            <ObjectDataProvider x:Key="FindTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:FindTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <ObjectDataProvider x:Key="HttpMethods" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:HttpMethods"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>

            <ObjectDataProvider x:Key="PostTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:PostTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <ObjectDataProvider x:Key="CookieTypes" 
                        MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:CookieTypes"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
        </ResourceDictionary>
    </inter:PluginConfigForm.Resources>
    <DockPanel DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}, Path=Config}">
        <TabControl DockPanel.Dock="Top">
            <TabItem Header="{DynamicResource Plugin_WebDownloader_GeneralSetting}">
                <DockPanel Margin="5" MinWidth="400" MaxWidth="600">
                    <AdornerDecorator DockPanel.Dock="Top">
                        <ComboBox x:Name="cbEncoding" ItemsSource="{Binding Path=EncodingList, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}}"
                                      SelectedItem="{Binding Path=EncodingContent, UpdateSourceTrigger=PropertyChanged}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=DisplayName}"></TextBlock>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                            <sm:WatermarkService.Titlemark>
                                <TextBlock Text="{DynamicResource Plugin_WebDownloader_Encode}" TextAlignment="Right"></TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </ComboBox>
                    </AdornerDecorator>
                    <AdornerDecorator DockPanel.Dock="Top">
                        <ComboBox x:Name="cbHttpGetType"
                                ItemsSource="{Binding Source={StaticResource HttpMethods}}"
                                SelectedItem="{Binding Path=HttpMethod, UpdateSourceTrigger=PropertyChanged}">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock Text="{DynamicResource Plugin_WebDownloader_HTTPMethods}" TextAlignment="Right"></TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </ComboBox>
                    </AdornerDecorator>
                    <Border DockPanel.Dock="Top" Margin="30,0,2,0" BorderBrush="Gray" BorderThickness="1"
                                 Visibility="{Binding ElementName=cbHttpGetType, Path=SelectedValue, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter={x:Static local:HttpMethods.POST}}">
                        <DockPanel Margin="5">
                            <AdornerDecorator DockPanel.Dock="Top">
                                <ComboBox x:Name="cbPostTypes"
                                              ItemsSource="{Binding Source={StaticResource PostTypes}}"
                                              SelectedItem="{Binding Path=PostType, UpdateSourceTrigger=PropertyChanged}">
                                    <ComboBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Path=., Converter={StaticResource FindUILanguageConverter}, ConverterParameter='Plugin_WebDownloader_PostTypes_'}"></TextBlock>
                                        </DataTemplate>
                                    </ComboBox.ItemTemplate>
                                    <sm:WatermarkService.Titlemark>
                                        <TextBlock Text="{DynamicResource Plugin_WebDownloader_PostType}" TextAlignment="Right"></TextBlock>
                                    </sm:WatermarkService.Titlemark>
                                </ComboBox>
                            </AdornerDecorator>
                            <AdornerDecorator DockPanel.Dock="Top"
                                          Visibility="{Binding ElementName=cbPostTypes, Path=SelectedValue, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter={x:Static local:PostTypes.CustomContent}}">
                                <TextBox Text="{Binding Path=PostDate, UpdateSourceTrigger=PropertyChanged}" 
                                         MinHeight="100" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto">
                                    <sm:WatermarkService.Titlemark>
                                        <TextBlock Text="{DynamicResource Plugin_WebDownloader_PostContent}" TextAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
                                    </sm:WatermarkService.Titlemark>
                                </TextBox>
                            </AdornerDecorator>
                        </DockPanel>
                    </Border>
                    <AdornerDecorator DockPanel.Dock="Top">
                        <ComboBox x:Name="cbGetType"
                                ItemsSource="{Binding Source={StaticResource FindTypes}}"
                                SelectedItem="{Binding Path=FindType, UpdateSourceTrigger=PropertyChanged}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=., Converter={StaticResource FindUILanguageConverter}, ConverterParameter='Plugin_WebDownloader_FindTypes_'}"></TextBlock>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                            <sm:WatermarkService.Titlemark>
                                <TextBlock Text="{DynamicResource Plugin_WebDownloader_GetType}" TextAlignment="Right"></TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </ComboBox>
                    </AdornerDecorator>

                </DockPanel>
            </TabItem>
            <TabItem Header="{DynamicResource Plugin_WebDownloader_AdvanceSetting}">
                <DockPanel Width="600">
                    <AdornerDecorator DockPanel.Dock="Top">
                        <TextBox Text="{Binding Path=UrlReferrer}"  MouseDoubleClick="tbUrl_MouseDoubleClick_1">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock TextAlignment="Right">UrlReferrer</TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </TextBox>
                    </AdornerDecorator>
                    <AdornerDecorator DockPanel.Dock="Top">
                        <TextBox Text="{Binding Path=Accept}" MouseDoubleClick="tbUrl_MouseDoubleClick_1">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock TextAlignment="Right">Accept</TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </TextBox>
                    </AdornerDecorator>
                    <AdornerDecorator DockPanel.Dock="Top">
                        <TextBox Text="{Binding Path=UserAgent}" MouseDoubleClick="tbUrl_MouseDoubleClick_1">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock TextAlignment="Right">User-Agent</TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </TextBox>
                    </AdornerDecorator>
                    <AdornerDecorator DockPanel.Dock="Top">
                        <TextBox Text="{Binding Path=AcceptCharset}" MouseDoubleClick="tbUrl_MouseDoubleClick_1">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock TextAlignment="Right">Accept-Charset</TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </TextBox>
                    </AdornerDecorator>
                    <AdornerDecorator DockPanel.Dock="Top">
                        <TextBox Text="{Binding Path=AcceptLanguage}" MouseDoubleClick="tbUrl_MouseDoubleClick_1">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock TextAlignment="Right">Accept-Language</TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </TextBox>
                    </AdornerDecorator>
                    <AdornerDecorator DockPanel.Dock="Top">
                        <TextBox Text="{Binding Path=ContentType}" MouseDoubleClick="tbUrl_MouseDoubleClick_1">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock TextAlignment="Right">Content-Type</TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </TextBox>
                    </AdornerDecorator>
                    <DockPanel DockPanel.Dock="Top">
                        <AdornerDecorator DockPanel.Dock="Top">
                            <ComboBox x:Name="cbCookieTypes"
                                              ItemsSource="{Binding Source={StaticResource CookieTypes}}"
                                              SelectedItem="{Binding Path=CookieType, UpdateSourceTrigger=PropertyChanged}">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=., Converter={StaticResource FindUILanguageConverter}, ConverterParameter='Plugin_WebDownloader_PostTypes_'}" />
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                                <sm:WatermarkService.Titlemark>
                                    <TextBlock TextAlignment="Right" VerticalAlignment="Bottom">Cookie</TextBlock>
                                </sm:WatermarkService.Titlemark>
                            </ComboBox>
                        </AdornerDecorator>
                        <AdornerDecorator DockPanel.Dock="Top"
                                          Visibility="{Binding ElementName=cbCookieTypes, Path=SelectedValue, Converter={StaticResource EnumToVsibleConverter}, ConverterParameter={x:Static local:CookieTypes.CustomContent}}">
                            <TextBox 
                                Text="{Binding Path=Cookie}" 
                                MouseDoubleClick="tbUrl_MouseDoubleClick_1" TextWrapping="Wrap">
                                <sm:WatermarkService.Titlemark>
                                    <TextBlock TextAlignment="Right" VerticalAlignment="Bottom">Cookie</TextBlock>
                                </sm:WatermarkService.Titlemark>
                            </TextBox>
                        </AdornerDecorator>
                    </DockPanel>
                </DockPanel>
            </TabItem>
            <TabItem Header="{DynamicResource Plugin_WebDownloader_WebExplorer}" Height="23" VerticalAlignment="Bottom">
                <DockPanel Width="1000">
                    <AdornerDecorator DockPanel.Dock="Top">
                        <TextBox Name="tbUrl"
                                     Text="{Binding Config.Url, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type inter:PluginConfigForm}}}"
                                     KeyDown="tbUrl_KeyDown_1"
                                     MouseDoubleClick="tbUrl_MouseDoubleClick_1">
                            <sm:WatermarkService.Titlemark>
                                <TextBlock Text="{DynamicResource Plugin_WebDownloader_Url}" HorizontalAlignment="Right"></TextBlock>
                            </sm:WatermarkService.Titlemark>
                        </TextBox>
                    </AdornerDecorator>
                    <Border DockPanel.Dock="Top"
                                 BorderThickness="1" BorderBrush="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Margin="2">
                        <WebBrowser Name="wbExplorer" MinHeight="450"
                                        Navigated="wbExplorer_Navigated" 
                                        Navigating="wbExplorer_Navigating_1"/>
                    </Border>
                </DockPanel>
            </TabItem>
        </TabControl>
        <TextBlock Style="{StaticResource InfoStyle}" DockPanel.Dock="Top" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type inter:PluginConfigForm}}, Path=ToolTip}" TextWrapping="Wrap"/>
    </DockPanel>
</inter:PluginConfigForm>
